package pl.przewozy;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by lnowak on 23.10.13.
 */
public class Schedule {
    public String  trainNo;
    public String  destination;// station
    public String  delay;      // in minutes
    public String  nearBy;     // station
    public String  updateTime;

    public Schedule (String textToParse) throws ParseException {
        ArrayList<String> tags = new ArrayList<String>();
        parseToTags(textToParse, tags);
        assignValues(tags);
    }

    private void assignValues(ArrayList<String> tags) {
        trainNo = tags.get(0);
        destination = tags.get(1);
        delay = tags.get(2);
        nearBy = tags.get(3);
        updateTime = tags.get(4);
        if ( -1 != updateTime.indexOf(" "))
            updateTime = updateTime.substring(updateTime.indexOf(" ") + 1, updateTime.length());
        else
            updateTime = tags.get(4);
    }

    private void parseToTags(String textToParse, ArrayList<String> tags) {
        int first = 0; int last = 0;
        while (-1 != first && -1 != last) {
            last = textToParse.indexOf("|",first);
            if ( -1 != last) {
                String str = textToParse.substring(first,last);
                tags.add(str);
                first = last + 1;
            }
        }
    }

}


